import { useAppSelector } from '@/redux/store';
import { useState } from 'react';
import { CategoryList } from './CategoryList';
import { EntTradeSelect, TradeSelect } from './TradeSelect';

interface CategoryAndTradePorps {
  type: number;
  onChange?(value: { pName?: string; cName?: string; classId?: string }): void;
}
export default function CategoryAndTrade({ onChange, type }: CategoryAndTradePorps) {
  const [trade, setTrade] = useState<string>('');
  const { entId, organizationType } = useAppSelector((state) => state.loginEnt); //organizationType 1:协会，0：企业

  return (
    <div className="page_main">
      <div style={{ marginBottom: '24px' }}>
        <span>所属行业：</span>
        {organizationType == 1 ? (
          <TradeSelect value={trade} onChange={setTrade} style={{ width: 200 }} />
        ) : entId ? (
          <EntTradeSelect value={trade} onChange={setTrade} style={{ width: 200 }} entId={entId} />
        ) : null}
      </div>
      <div>
        <CategoryList type={type} trade={trade} onChange={(e) => onChange && onChange(e)} />
      </div>
    </div>
  );
}
